var wxCharts = require("../../utils/wxcharts.js");//相对路径
const app = getApp();
Page({

  data:{
    imageWidth:0,
    dataIncome:[],
    dataExpend:[],
    income:new Array(14).fill(0),
    expend:new Array(14).fill(0)
  },
  onLoad:function(){
    for(var i=0;i<app.globalData.dataArray.length;++i){
      var tempIndex = true;
      if(app.globalData.dataArray[i].inputIndex=="收入"){
        for(var j=0;j<this.data.dataIncome.length;++j){
          if(this.data.dataIncome[j]==app.globalData.dataArray[i].inputData){
            tempIndex = false;
            break;
          }
        }
        if(tempIndex){
          this.data.dataIncome.push(app.globalData.dataArray[i].inputData);
        }
      }
      else{
        for(var j=0;j<this.data.dataExpend.length;++j){
          if(this.data.dataExpend[j]==app.globalData.dataArray[i].inputData){
            tempIndex = false;
            break;
          }
        }
        if(tempIndex){
          this.data.dataExpend.push(app.globalData.dataArray[i].inputData);
        }
      }
    }
    this.data.dataIncome.sort();
    this.data.dataExpend.sort();
    for(var i=0;i<this.data.dataIncome.length;++i){
      for(var j=0;j<app.globalData.dataArray.length;++j){
        if(app.globalData.dataArray[j].inputIndex=="收入"&&app.globalData.dataArray[j].inputData==this.data.dataIncome[i]){
          this.data.income[i] += parseInt(app.globalData.dataArray[j].inputPrice);
        }
      }
    }
    for(var i=0;i<this.data.dataExpend.length;++i){
      for(var j=0;j<app.globalData.dataArray.length;++j){
        if(app.globalData.dataArray[j].inputIndex=="支出"&&app.globalData.dataArray[j].inputData==this.data.dataExpend[i]){
          this.data.expend[i] += parseInt(app.globalData.dataArray[j].inputPrice);
        }
      }
    }
    this.data.income.slice(0,this.data.dataIncome.length);
    this.data.expend.slice(0,this.data.dataExpend.length);
  },
  onShow:function(){
    new wxCharts({
      canvasId: 'columnCanvas_in',
      type: 'column',
      categories: this.data.dataIncome,
      series: [{
          name: '收入',
          data: this.data.income
      }],
      yAxis: {
          format: function (val) {
              return val + '元';
          },
          /*max:400,
          min:0*/
      },
      width: wx.getSystemInfoSync().windowWidth-10,
      height: 200
  });
  new wxCharts({
    canvasId: 'columnCanvas_out',
    type: 'column',
    categories: this.data.dataExpend,
    series: [{
        name: '支出',
        data: this.data.expend
    }],
    yAxis: {
        format: function (val) {
            return val + '元';
        },
        /*max:400,
        min:0*/
    },
    width: wx.getSystemInfoSync().windowWidth-10,
    height: 200
});
  }

})
